<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<script>
// 用settimeout 实现一个setinterval // setinterval缺陷？

function myInterval (cb, time) {
    let fn = arguments.callee
    let timer
    let interval = function () {
        timer = setTimeout(function(){
            // console.log(cb)
            cb();
            interval()
        },time);
    }
    interval()
    return {
        clear:() => {
            clearTimeout(timer)
        }
    }
}

let a  = myInterval(()=> {
    console.log('哈哈哈')
}, 1000)



</script>
</body>
</html>